package com.jwthhealth_pub.old.physicalfitness.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.app.App;
import com.jwthhealth_pub.common.preference.PreferenceKey;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.old.common.Constant;
import com.jwthhealth_pub.old.physicalfitness.view.adapter.PortraitAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/1/14.
 */
public class IndividualHeadPortraitActivity extends Activity {
    @BindView(R.id.green)
    View view;
    @BindView(R.id.rb)
    RecyclerView rv;
    @BindView(R.id.sign_topbar)
    TitleLayout signTopbar;
    private PortraitAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_portrait);
        ButterKnife.bind(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        initTop();
        initRv();
    }

    private void initRv() {
        GridLayoutManager layout = new GridLayoutManager(this, 3);
        layout.setSmoothScrollbarEnabled(false);
        rv.setLayoutManager(layout);
        adapter = new PortraitAdapter(this);
        rv.setAdapter(adapter);
    }

    private void initTop() {
        signTopbar.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }

    @OnClick(R.id.btn_save)
    public void onClick() {
        int selectPos = adapter.getSelectPos();
        if (selectPos != -1) {
            Intent intent = new Intent();
            intent.putExtra(Constant.SELECTEDPOS, selectPos);
            int mapmip = adapter.getImgs()[selectPos];
            App.preferenceUtil.putInt(PreferenceKey.PORTRAIT, mapmip);
            App.preferenceUtil.putInt(PreferenceKey.PORTRAITPOS, selectPos);
            setResult(RESULT_OK, intent);
            finish();
        } else {
            Toast.makeText(this, getResources().getString(R.string.individual_title_protrait_chocie_portrait), Toast.LENGTH_SHORT).show();
        }
    }
}
